#!/usr/bin/groovy
@Library('test-shared-library') _

properties(
        [
                parameters(
                        [
                                booleanParam(name: 'runBasicBenchmarks', defaultValue: true, description: 'Run Basic Benchmarks'),
                                booleanParam(name: 'runBigDataH2OToSparkBenchmarks', defaultValue: false, description: 'Run Big Data H2O to Spark Benchmarks'),
                                booleanParam(name: 'runBigDataSparkToH2OBenchmarks', defaultValue: false, description: 'Run Big Data Spark to H2O Benchmarks')
                        ]
                ),
                pipelineTriggers([cron('H 8 * * 6')]),
                buildDiscarder(logRotator(numToKeepStr: '10'))
        ]
)

node("docker") {
    cleanWs()
    checkout scm
    def commons = load 'ci/commons.groovy'
    commons.withAWSCredentials {

        stage("Basic Benchmarks") {
            if (params.runBasicBenchmarks.toBoolean()) {
                commons.withSparklingWaterDockerImage {
                    sh "./gradlew :sparkling-water-benchmarks:runBenchmarks -Pspark=2.4 -Paws_access_key=${AWS_ACCESS_KEY_ID} -Paws_secret_key=${AWS_SECRET_ACCESS_KEY} -Paws_ssh_public_key=default"
                    arch '**/output/*'
                }
            }
        }

        stage("H2O to Spark Conversion Benchmarks") {
            if (params.runBigDataH2OToSparkBenchmarks.toBoolean()) {
                commons.withSparklingWaterDockerImage {
                    sh "./gradlew :sparkling-water-benchmarks:runBigDataH2OtoSparkConversionBenchmarks -Pspark=2.4 -Paws_access_key=${AWS_ACCESS_KEY_ID} -Paws_secret_key=${AWS_SECRET_ACCESS_KEY} -Paws_ssh_public_key=default"
                    arch '**/output/*'
                }
            }
        }

        stage("Spark to H2O Conversion Benchmarks") {
            if (params.runBigDataSparkToH2OBenchmarks.toBoolean()) {
                commons.withSparklingWaterDockerImage {
                    sh "./gradlew :sparkling-water-benchmarks:runBigDataSparkToH2OConversionBenchmarks -Pspark=2.4 -Paws_access_key=${AWS_ACCESS_KEY_ID} -Paws_secret_key=${AWS_SECRET_ACCESS_KEY} -Paws_ssh_public_key=default"
                    arch '**/output/*'
                }
            }
        }
    }
}
